<?php 
	ini_set("include_path", ".:../:./includes:../includes");
	//error_reporting(0);
	require_once("includes/constants.php");
	require_once("includes/database.php");
	require_once("includes/common.php");
	require_once("includes/template.php"); 
	
	head("Manage Tasks");
	
	$allOutstanding=false;
	$employeeFilter=false;
	$dateFilter=false;
	$orderFilter=false;
	
	// unset($_SESSION[TASKS]);

	if (isset($_REQUEST['employeeID']) && $_REQUEST['employeeID'] != "" ) {
		$employeeFilter = true;
		$employeeID = trim($_REQUEST['employeeID']);
		$_SESSION[TASKS] = getOutstandingTasksForEmployee($employeeID);  
	}
	else if (isset($_REQUEST['dateAssigned']) && $_REQUEST['dateAssigned'] != "") {		
		$dateFilter = true;
		$dateAssigned = trim($_REQUEST['dateAssigned']);
		$_SESSION[TASKS] = getTasksByDate($dateAssigned); 
	}
	else if (isset($_REQUEST['orderID']) && $_REQUEST['orderID'] != "") {		
		$orderFilter = true;
		$orderID = trim($_REQUEST['orderID']);
		$_SESSION[TASKS] = getTasksByOrder($orderID);
	}	
	else {//all
 		$allOutstanding = true;
		$_SESSION[TASKS] = getOutstandingTasks(); 			
	}	
 
	 	
	
?>
<div style="padding: 20px 20px 20px 20px; ">
	<table align="center">
		 <tr>
		 	<td>
		 		<label for="orderID">
		 			Order ID
		 		<label>
		 	</td>
		 	<td>
		 		<input type="text" name="orderID" value="" />
		 	</td>
		 	<td rowspan="3" align="center" valign="top" >
		 		 <?php makeButton("SEARCH", "manageTasks.php"); ?>
		 	</td>							
		 </tr>
		 <tr>
		 	<td>
		 		<label for="employeeID">
		 			Employee ID
		 		<label>
		 	</td>
		 	<td>
		 		<input type="text" name="employeeID" value="" />
		 	</td>
		 </tr>	
		 <tr>
		 	<td>
		 		<label for="dateAssigned">
		 			Items Due
		 		<label>
		 	</td>
		 	<td>
		 		<input type="text" name="dateAssigned" value="" />
		 	</td>
		 </tr>	
		 	 
	</table>
</div>			
<?php if (!isset($_SESSION[TASKS]) || $_SESSION[TASKS] == null) { ?>
	<div>
	 There are no matching tasks. Press button to view Outstanding tasks.	

	</div>

<?php } else { ?>


<table cellspacing="5px"  width="100%">	
	<tr>
		<td>
			&nbsp;
		</td>
		<td class="button1">
			Order ID
		</td>		
		<td class="button1">
			Order Item ID
		</td>
		<td class="button1">
			Employee ID
		</td>	
		<td class="button1">
			Employee Name
		</td>									
		<td class="button1">
			Order Due
		</td>			
		<td class="button1">
			Item Due
		</td>	
		<td class="button1">
			Hours
		</td>		
		
					
	</tr>
	<?php 
		$count = count($_SESSION[TASKS]);?>
		<input type="hidden" name="taskCount" id="taskCount" value=<?php echo $count; ?> />
	<?php 	foreach ($_SESSION[TASKS] as $index =>$task) {
	?>
	
	<tr >
		<td align="right">
			<input type=radio id="selectedTask<?php echo $index; ?>" name="selectedTask" value="<?php echo $index;?>" /> 
		</td>
		<td class="button2">
			<?php echo $_SESSION[TASKS][$index]['o_order_id']; ?>
		</td>		
		<td class="button2">
			<?php echo $_SESSION[TASKS][$index]['oi_item_id']; ?>
		</td>
		<td class="button2">
			<?php echo $_SESSION[TASKS][$index]['t_employee_id']; ?>
		</td>
		<td class="button2">
			<?php echo $_SESSION[TASKS][$index]['e_firstname'] .  " " . $_SESSION[TASKS][$index]['e_surname']; ?>
		</td>
		<td class="button2">
			<?php echo $_SESSION[TASKS][$index]['o_due_date']; ?>
		</td>
		<td class="button2">
			<?php echo $_SESSION[TASKS][$index]['t_date_assigned']; ?>
		</td>		
		<td class="button2">
			<?php echo $_SESSION[TASKS][$index]['t_hours_of_work']; ?>
		</td>			
	</tr>	
	<?php 	
		}
	?>
</table>
<?php } ?>


<?php if (isset($_SESSION[TASKS]) && $_SESSION[TASKS] != null)  
		foot("REASSIGN","reassignTask.php", "PRINT", "printTasks.php");		

	else {
		 
		foot("VIEW", "manageTasks.php?employeeID=&amp;orderID=&amp;dateAssigned=");
	}
?>

	
